import DataBus from '../databus'
let databus = new DataBus()
let diamondSize = databus.diamondSize
/**
 * 游戏基础的精灵类
 */
export default class Sprite {
  constructor(imgSrc = '', x = 0, y = 0, width = 0, height = 0) {
    this.img     = new Image()
    this.img.src = imgSrc

    this.x = x
    this.y = y
    this.w = width
    this.h = height
  }

  /**
   * 将精灵图绘制在canvas上
   */
  drawToCanvas(ctx) {

    ctx.drawImage(
      this.img,
      this.x * diamondSize,
      this.y * diamondSize,
      this.w * diamondSize,
      this.h * diamondSize
    )
  }
}
